package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.common.service.exception.GuiguException;
import com.atguigu.spzx.manager.mapper.ProductSpecMapper;
import com.atguigu.spzx.manager.service.ProductSpecService;
import com.atguigu.spzx.model.entity.product.ProductSpec;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class ProductSpecServiceImpl implements ProductSpecService {
    @Autowired
    private ProductSpecMapper productSpecMapper;
    @Override
    public PageInfo<ProductSpec> findProductSpecByPage(Integer current, Integer size) {
        PageHelper.startPage(current,size);
        List<ProductSpec> productSpecList=productSpecMapper.findProductSpecAll();
        PageInfo<ProductSpec> productSpecPageInfo = new PageInfo<>(productSpecList);
        return productSpecPageInfo;
    }

    @Override
    public void save(ProductSpec productSpec) {
        if(productSpec==null){
            throw new GuiguException(ResultCodeEnum.DATA_ERROR);
        }
        productSpecMapper.insertProductSpec(productSpec);
    }

    @Override
    public void updateById(ProductSpec productSpec) {
        productSpecMapper.updateById(productSpec);
    }

    @Override
    public void deleteById(Long id) {
        productSpecMapper.deleteById(id);
    }

    /**
     * 查询所有商品规格
     * @return
     */
    @Override
    public List<ProductSpec> FindAllProductSpec() {
     return    productSpecMapper.findProductSpecAll();

    }
}
